﻿Public Class ErrorAnalyzer
    Public Shared Function GetErrorMessages(ByVal raw As String) As List(Of ErrorMessage)
        Dim lines() As String = raw.Split(Chr(13))
        Dim result As New List(Of ErrorMessage)

        For Each line As String In lines
            Dim message As New ErrorMessage
            Dim tokens() As String = line.Trim.Split(":")

            If tokens.Count > 5 Then
                message.FullMessage = line.Trim()

                '' First and second token belongs to full file path
                message.FullFilename = tokens(0) & ":" & tokens(1)
                message.Filename = message.FullFilename.Substring(message.FullFilename.LastIndexOf("\") + 1)

                '' Third token belongs to line number
                message.Line = CInt(tokens(2))

                '' Fourth token belongs to column number
                message.Col = CInt(tokens(3))

                '' Fifth refers to type of error (error or warning)
                Select Case tokens(4).Trim
                    Case "error"
                        message.ErrorType = ErrorType.ErrorMsg
                    Case "warning"
                        message.ErrorType = ErrorType.WarningMsg
                End Select

                message.Message = tokens(5)
                result.Add(message)
            End If
        Next

        Return result
    End Function
End Class
